#include <bits/stdc++.h>

using namespace std;

class Solution
{
public:
    int totalFruit(vector<int> &fruits)
    {
        int ans = 0, n = fruits.size();
        unordered_map<int, int> fkinds;
        int left = 0;
        for (int right = 0; right < n; ++right)
        {
            fkinds[fruits[right]]++;
            for (; left < right && fkinds.size() > 2; ++left)
            {
                int topop = fruits[left];
                if (--fkinds[topop] == 0)
                    fkinds.erase(topop);
            }
            ans = max(right - left + 1, ans);
        }
        return ans;
    }
};

int main()
{

    // system("pause");
    return 0;
}
